package com.example.jl.bethinner.util;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.ActionProvider;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.SubMenu;
import android.view.View;

import com.example.jl.bethinner.R;
import com.example.jl.bethinner.activity.DetailActivity;
import com.example.jl.bethinner.activity.EditListDemoActivity;


public class PlusActionProvider extends ActionProvider {

    private Context context;

    public PlusActionProvider(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public View onCreateActionView() {
        return null;
    }

    @Override
    public void onPrepareSubMenu(SubMenu subMenu) {
        subMenu.clear();
        subMenu.add("添加好友")
                .setIcon(R.mipmap.add_friends_)
                .setOnMenuItemClickListener(new OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        Intent intent = new Intent(context, DetailActivity.class);
                        context.startActivity(intent);
                        return true;
                    }
                });
        subMenu.add("发起群聊")
                .setIcon(R.mipmap.ofm_group_chat_icon)
                .setOnMenuItemClickListener(new OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        Intent intent = new Intent(context, EditListDemoActivity.class);
                        context.startActivity(intent);
                        return true;
                    }
                });
    }

    @Override
    public boolean hasSubMenu() {
        return true;
    }

    @Override
    public boolean onPerformDefaultAction() {
        return super.onPerformDefaultAction();
    }
}